/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.colegiatura.tarea;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.cip.esymons.colegiatura.bc.ColegiadoDeporteDelegate;
import org.cip.esymons.colegiatura.be.ColegiadoDeporte;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 *
 * @author WILLIAM
 */
public class TareaSancionDeporte implements Job {

    private ColegiadoDeporteDelegate delegadoDeporte;
    private List<ColegiadoDeporte> listaDep;


    public void removerSancionDeporte(){

        try{
            listaDep = new ArrayList<ColegiadoDeporte>();
            listaDep = delegadoDeporte.findAll();
            String DATE_FORMAT = "dd/MM/yyyy";
            SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);

            System.out.println("lista Deporte : "+listaDep.size());
            for(ColegiadoDeporte colDep : listaDep){

             if(colDep.getCde_fechaFinSancion()!=null){
//                String f1 = sdf.format(colDep.getCde_fechaFinSancion());
//                String f2 = sdf.format(new Date());
                if(colDep.getCde_fechaFinSancion().compareTo(new Date())==0 || colDep.getCde_fechaFinSancion().compareTo(new Date())< 0){
//                if(f1.equals(f2)){
                    colDep.setCde_fechaIniSancion(null);
                    colDep.setCde_fechaFinSancion(null);
                    colDep.setCdeSancion(false);
                    System.out.println("deporte modificado: "+colDep.getCdeSancion());
                    delegadoDeporte.edit(colDep);

                }
              }
            }
        }catch(Exception ex){
            System.out.println("error : "+ex);
        }
    }

    public void execute(JobExecutionContext context) 
            throws JobExecutionException{

        System.out.println("Ejecutandose Tarea ...");
        removerSancionDeporte();

      

        
    }
}
